home *** CD-ROM | disk | FTP | other *** search
- Path: news.infi.net!usenet
- From: Steve Rountree <srndtree@infi.net>
- Newsgroups: comp.lang.c
- Subject: Re: Recursion Question
- Date: Sat, 06 Apr 1996 12:06:36 -0800
- Organization: InfiNet
- Message-ID: <3166CECC.354E@infi.net>
- References: <4k14o1$2k2@isis.fiu.edu>
- NNTP-Posting-Host: h-agate.dc.infi.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- A non-recursive method: (assuming a 16 bit integer)
-
- for(count=32768;count>0;count/=2){
- printf("%d",(num & count ? 1 : 0));
- }
-
-
- Recursively:
-
- int Binum(int value,int num){
- if(value){
- printf("%d",(value & num ? 1 : 0));
- Binum(value/2,num);
- }
- else
- return(0);
- }
-
-
- I know the first one works and I think that the second one is
- structured properly. If not, play with it. I think that it is close.
- These, of course, only address the problem with printing out as you go.
- You can also of course store the result of each "&" operation in a
- integer array.
-
- Steve Rountree
-
- Mark Romano wrote:
- >
- > I am trying to find some recursive functions that will convert a number into
- > a binary. I need one that will print out the numbers as they are
- > generated and I also need one that will hold the binary digits in memory
- > and then printed out with a single printf statement. Can any one help??
- >
- >
- > __________________________________________________________
- > | |
- > | Sent to you by: mark@serss1.fiu.edu |
- > | |
- > |________________________________________________________|
-